import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface AdminUser {
	avatar: string;
	nickname: string;
	username: string;
	password: string;
	permission: string;
	createdAt?: string;
	updatedAt?: string;
}

// 后台管理用户
const AdminUserSchema = new mongoose.Schema<AdminUser>(
	{
		avatar: {
			type: String,
			default: '',
		},
		nickname: {
			type: String,
			required: true,
		},
		username: {
			type: String,
			required: true,
			unique: true,
		},
		password: {
			type: String,
			required: true,
		},
		permission: {
			type: String,
			required: true,
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'admin_users',
	}
);

export const AdminUserModel = mongoose.model('AdminUser', AdminUserSchema);
